﻿using AutoMapper;
using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command.RabbitBWss;

namespace U.B.WriteApi.CommandHander.RabbitBWDD
{
    public class AddKillCommmandHander : IRequestHandler<AddKillCommmand, ApiResult<object>>
    {
        public readonly IRepistory<Kill> _killRepository;
        public readonly IMapper _mapper;

        public AddKillCommmandHander(IRepistory<Kill> killRepository, IMapper mapper)
        {
            _killRepository = killRepository;
            _mapper = mapper;
        }
        /// <summary>
        /// 屠宰信息添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<ApiResult<object>> Handle(AddKillCommmand request, CancellationToken cancellationToken)
        {
            ApiResult<object> apiResult=new ApiResult<object>();
            var result = _mapper.Map<Kill>(request);
            _killRepository.Add(result);
            apiResult.Data = result;
            apiResult.code =Renum.添加成功;
            apiResult.Message = Renum.添加成功.ToString();
            return Task.FromResult(apiResult);
        }
    }
}
